package edu.szu.huhanpeng.doodlingFight.controller.showController.gameStart 
{
	import com.bit101.components.Label;
	import com.bit101.components.Panel;
	import com.bit101.components.PushButton;
	import com.bit101.components.Text;
	import com.greensock.TweenLite;
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.model.GameProxy;
	import edu.szu.huhanpeng.doodlingFight.view.StagePanelMed;
	import flash.events.Event;
	import org.puremvc.as3.interfaces.IAsyncCommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.AsyncCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class SetPlayerMsgSc extends AsyncCommand implements IAsyncCommand, INotifier 
	{
		
		
		//面板参数
		private static const PANEL_WIDTH:int = 250;
		private static const PANEL_HEIGHT:int = 170;
		
		private static const PANEL_X:int = 540;
		private static const PANEL_Y:int = 70;
		
		private static const FADE_OFFSET:int = 50;
		
		//按钮参数
		private static const BTN_WIDTH:int = 60;
		private static const BTN_HEIGHT:int = 25;
		
		private static const BTN_X:int = (PANEL_WIDTH - BTN_WIDTH) /2 ;
		private static const BTN_Y:int = TXT_P_Y + Y_GAP;
		
		private static const BTN_LABEL:String = "确定";
		
		//label参数
		private static const LABEL_WIDTH:int = 145;
		
		private static const LABEL_X:int = (PANEL_WIDTH - LABEL_WIDTH) / 2;
		private static const LABEL_Y:int = 20;
		
		private static const LABEL_STR:String = "请输入对阵双方姓名和胜利分数";
		
		//txt参数
		private static const TXT_WIDTH:int = 100;
		private static const TXT_HEIGHT:int = 20;
		
		private static const X_OFFSET:int = 20;
		private static const Y_GAP:int = 30;
		
		private static const TXT_A_X:int = LABEL_X + X_OFFSET;
		private static const TXT_A_Y:int = LABEL_Y + Y_GAP;
		
		private static const TXT_B_X:int = TXT_A_X;
		private static const TXT_B_Y:int = TXT_A_Y + Y_GAP;
		
		private static const TXT_P_X:int = TXT_A_X;
		private static const TXT_P_Y:int = TXT_B_Y + Y_GAP;
		
		private static const TXT_A_STR:String = "玩家1";
		private static const TXT_B_STR:String = "玩家2";
		private static const TXT_P_STR:String = "100";
		private static const WIN_SCORE:int = 100;
		
		private var _txtA:Text;
		private var _txtB:Text;
		private var _txtP:Text;
		
		override public function execute(note:INotification):void 
		{
			var stage:Panel = facade.retrieveMediator( StagePanelMed.NAME ).getViewComponent() as Panel;
			
			var panel:Panel = new Panel( stage, PANEL_X + FADE_OFFSET, PANEL_Y );
			panel.setSize( PANEL_WIDTH, PANEL_HEIGHT );
			panel.alpha = 0;
			TweenLite.to( panel, GlobalConst.setting.FADEIN, { alpha:1, x:PANEL_X } );
			
			
			var label:Label = new Label( panel, LABEL_X, LABEL_Y, LABEL_STR );
			_txtA = new Text( panel, TXT_A_X, TXT_A_Y, TXT_A_STR );
			_txtB = new Text( panel, TXT_B_X, TXT_B_Y, TXT_B_STR );
			_txtP = new Text( panel, TXT_P_X, TXT_P_Y, TXT_P_STR );
			_txtA.setSize( TXT_WIDTH, TXT_HEIGHT );
			_txtB.setSize( TXT_WIDTH, TXT_HEIGHT );
			_txtP.setSize( TXT_WIDTH, TXT_HEIGHT );
			
			var btn:PushButton = new PushButton( panel, BTN_X, BTN_Y, BTN_LABEL, onClick );
			btn.setSize( BTN_WIDTH, BTN_HEIGHT );
			
		}
		
		private function onClick(e:Event):void 
		{
			var gameProxy:GameProxy = facade.retrieveProxy( GameProxy.NAME ) as GameProxy;
			if ( _txtA.text.length != 0 ) 
			{
				gameProxy.setOpName( _txtA.text );
			}
			else
			{
				gameProxy.setOpName( TXT_A_STR );
			}			
			
			if ( _txtB.text.length != 0 ) 
			{
				gameProxy.setTpName( _txtB.text );
			}
			else
			{
				gameProxy.setTpName( TXT_B_STR );
			}			
			
			var score:int = int(_txtP.text);
			if ( score >= 0 ) 
			{
				gameProxy.setWinScore( score );
			}
			else
			{
				gameProxy.setWinScore( WIN_SCORE );
			}
			
			
			commandComplete();
		}
		
	}

}